package com.choudou5.solr.analyzer.factory;

import com.choudou5.solr.analyzer.filter.PinyinTransformTokenFilter;
import org.apache.lucene.analysis.TokenFilter;
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.util.TokenFilterFactory;

import java.util.Map;

/**
 * @name 拼音转换工厂
 * @author choudou5
 * @date 2018-7-23
 */
public class PinyinTransformTokenFilterFactory extends TokenFilterFactory {

    private boolean isOutChinese = true;
    private int minTermLenght = 2;

    public PinyinTransformTokenFilterFactory(Map<String, String> args)
    {
        super(args);
        this.isOutChinese = getBoolean(args, "isOutChinese", true);
        this.minTermLenght = getInt(args, "minTermLenght", 2);
        if (!args.isEmpty()) {
            throw new IllegalArgumentException("Unknown parameters: " + args);
        }
    }

    public TokenFilter create(TokenStream input)
    {
        return new PinyinTransformTokenFilter(input,  this.minTermLenght, this.isOutChinese);
    }
}
